'use strict';

const modelCheckQuery = {
  name: {
    type: 'string',
    min: 1,
    max: 100,
  },
  show: {
    type: 'string',
    min: 1,
    max: 1000,
  },
  num: {
    type: 'int',
    default: 0
  },
}

exports.index = async ctx => {
  const data = await ctx.service.skills.list();
  ctx.sendSuccess(data);
};

exports.create = async ctx => {
  ctx.validate(modelCheckQuery);
  await ctx.service.skills.create(ctx.w_body('name show num'))
  ctx.sendSuccess();
};

exports.update = async ctx => {
  ctx.validate(modelCheckQuery);
  ctx.validate({
    id: {
      type: 'mongo-id',
    },
  }, ctx.params);
  ctx.sendSuccess(await ctx.service.skills.update(ctx.params.id, ctx.w_body('name show num')));
};

exports.destroy = async ctx => {
  ctx.validate({
    id: {
      type: 'mongo-id',
    },
  }, ctx.params);
  await ctx.service.skills.destroy(ctx.params.id)
  ctx.sendSuccess();
};

